package controller

import (
	"im/dao"
	"im/requests"
)

type Posts struct {
	Base
}

func (p Posts) Get() {
	var param = requests.Pagination{
		1, 10,
	}
	p.Ctx.ReadQuery(&param)
	result, count, err := dao.NewAdminPosts().List(param)
	if err != nil {
		p.SendCry(err)
		return
	}
	var resp = map[string]interface{}{}
	resp["list"] = result
	resp["count"] = count
	p.SendSmile(resp)
}

func (p Posts) PutBy(id int64) {
	var param = dao.PostsPutByParam{}
	p.Ctx.ReadJSON(&param)
	err := dao.NewAdminPosts().Update(id, param)
	if err != nil {
		p.SendCry(err)
		return
	}
	p.SendSmile(nil)
}
